var scripts = [null,
    "LingUI/js/jqGrid/jquery.jqGrid.js",
    "LingUI/js/jqGrid/i18n/grid.locale-cn.js",
    "LingUI/js/control.js",
    "LingUI/js/jsutil/js/jquery.filterSearch.js",   //筛选搜索
    null];
var _grid_id = "#demo_stu_list_table";	//表格 选择器
var _pager_id = "#demo_stu_list_pager";	//表格页脚 选择器
ace.load_ajax_scripts(scripts, function() {
    $("#search").strongFilterSearch({
        inputFiled:"searchValue",				//搜索字段，不填默认为searchValue
        inputPlaceholder:"请输入服务名称、服务描述等关键字",		//占位符
        searchCallback : callback//,				//搜索按钮点击后回调
        //moreBtnShow:false ,					//更多按钮是否显示 默认为true
        //filter : ${filterData} 					//后台传递的json数据
        /*
         filter:[{
         filterName : "颜色", //筛选字段名称
         filterId : "color3", //筛选字段id
         filterValue : {		//筛选的值
         "红2色":"red",
         "白色":"white"
         }
         },
         {
         filterName : "大小",
         filterId : "size2",
         filterValue : {
         "大的":"big",
         "小的":"big1"
         }
         }]
         */
    });
    //搜索回调函数
    function callback(data){
        jQuery("#demo_stu_list_table").jqGrid('setGridParam', {
            url : "../user/getSystemList.do",
            mtype : "GET",
            postData:data //传递的数据
        }).trigger("reloadGrid");
    }


    //调整以适应页面大小  其中 $(".page-content") 为jqgrid的父级容器
    $(window).off('resize.jqGrid').on('resize.jqGrid', function () {
        setTimeout(function(){
            $(_grid_id).jqGrid("setGridWidth",$(".page-content").width());
            $(".ui-jqgrid-bdiv").width($(".page-content").width()+1);
        },50);
    });
    jQuery(_grid_id).jqGrid({
        mtype : "GET",
        url: "../authorization/getServiceList.do",
        colNames:['id','服务名称','服务描述','创建时间','操作'],
        colModel:[
            {name:'id',index:'id', width:0,  editable: true,  hidden:true},
            {name:'name',index:'name', width:0,  editable: true},
            {name:'desc',index:'desc', width:0,  editable: true},
            {name:'create_time',index:'create_time', width:0,  editable: true},
            {name:'action',index:'', width:100, fixed:false, sortable:false,align:'center', formatter:
                function(cellvalue, options, rowObject) {
                    var s='<div class=" action-buttons">'
                    s=s+  '<a class="green my-tooltip-link tooltip-primary " title="查看密钥" style="cursor:pointer" ><i class="ace-icon fa fa-search-plus bigger-130 " onclick="viewrows(\''+rowObject.id+'\')"></i></a>';
                    s=s+  '<a class="blue my-tooltip-link tooltip-primary" title="编辑" style="cursor:pointer" ><i class="ace-icon fa fa-pencil bigger-130 " onclick="editrows(\''+rowObject.id+'\')"></i></a>'    ;
                    s=s+  '<a class="red my-tooltip-link tooltip-primary" title="删除" style="cursor:pointer"><i class="ace-icon fa fa-trash-o bigger-130"  onclick="deleterows(\''+rowObject.id+'\')"></i></a>' ;
                    return s+'</div>';}
            }
        ],
        pager : _pager_id, //分页信息 放置的位置
        page : lui.pageNum(_grid_id)
    });
    //自定义工具栏 =============BEGIN======================//
    jQuery(_grid_id)
        .jqGrid('navGrid',_pager_id)
        .navButtonAdd( _pager_id,{
            //iconTitle : "新增",//图标下面显示（不填的话默认为title里面的值）
            buttonicon : "ace-icon fa fa-plus-circle purple",
            onClickButton: function(){
                url="#service/editService.jsp";
                toLocation(url);
            }
        })
        .navButtonAdd( _pager_id,{
            buttonicon : "ace-icon fa fa-pencil blue"
            //onClickButton : editrows
        })
        .navButtonAdd( _pager_id,{
            buttonicon : "ace-icon fa fa-trash-o red"
            //onClickButton : deleterows
        })
        .navButtonAdd( _pager_id,{
            buttonicon : "ace-icon fa fa-refresh orange",
            onClickButton : function(){
                callback();
            }
        });
    //自定义工具栏 =============END======================//

});

//删除
function deleterows(id){
    var con = confirm("你确定要删除该记录吗？");
    if(con){
        var json = {};
        json["id"] = id;
        $.post("../authorization/deleteService.do",
            {json:JSON.stringify(json)},
            function(data){
                if(data.success == "Y"){
                    alert("删除成功!");
                    jQuery(_grid_id).trigger("reloadGrid");
                }else{
                    alert("系统异常,请联系客服人员!");
                }
            },"json");

    }else{
        return;
    }
}
